package com.hqyj.base.controller;

import frame.base.controller.BaseController;
import com.hqyj.base.model.InfoProducts;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @ProjectName: ERP-System
 * @Package: com.hqyj.base.controller
 * @ClassName: infoProductsServiceController
 * @Author: LiYi
 * @Date: 2021-09-07 15:30
 */

@Controller
@RequestMapping("/baseController")
public class InfoProductsController extends BaseController {

    @RequestMapping("/product.do")
    public String queryAllByInfoUser(Model model){
        List<InfoProducts> infoProducts_db = infoProductsService.queryAllByInfoProducts();
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/infoProductsList";
    }


    @RequestMapping("/addInfoProducts.do")
    public String addInfoUser(Model model, InfoProducts infoProducts){
        infoProductsService.addInfoProducts(infoProducts);
        System.out.println(infoProducts + "已经获取到前端对象");
        List<InfoProducts> infoProducts_db = infoProductsService.queryAllByInfoProducts();
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/infoProductsList";
    }

    @RequestMapping("/deleteInfoProductsById.do")
    public String deleteInfoUserById(Model model, String Id){
        int urlId = Integer.parseInt(Id);
        infoProductsService.deleteInfoProductsById(urlId);
        List<InfoProducts> infoProducts_db = infoProductsService.queryAllByInfoProducts();
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/infoProductsList";
    }


    @RequestMapping("/updateInfoProductsUI.do")
    public String queryInfoUserById(Model model, String Id){
        int urlId = Integer.parseInt(Id);
        InfoProducts infoProducts_db = infoProductsService.queryInfoProductsById(urlId);
        System.out.println("查看数据的InfoProducts对象" + infoProducts_db);
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/updateInfoProducts";
    }
    @RequestMapping("/updateInfoProductById.do")
    public String updateInfoUserById(Model model, InfoProducts infoProducts){
        System.out.println("查看修改的数据" + infoProducts);
        infoProductsService.updateInfoProductById(infoProducts);
        List<InfoProducts> infoProducts_db = infoProductsService.queryAllByInfoProducts();
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/infoProductsList";
    }


    @RequestMapping("/queryFuzzyInfoProducts.do")
    public String queryFuzzyInfoSupplier(Model model, String keyword, HttpServletResponse response) throws IOException {
        System.out.println("前端的Keyword" + keyword);
        List<InfoProducts> infoProducts_db = infoProductsService.queryFuzzyInfoSupplier(keyword);
        model.addAttribute("infoProducts_db",infoProducts_db);
        return "view/base/infoproducts/infoProductsList";
    }
}
